[LeetCode 70]Climbing Stairs 爬楼梯
Problem description:
You are climbing a stair case. It takes n steps to reach to the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
Note: Given n will be a positive integer.
Example:
1 | Input: 2 |
问题描述:
假设你正在爬楼梯。需要 n 步你才能到达楼顶。
每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?
说明:给定 n 是一个正整数。
示例:
1 | 输入: 2 |
Solution:
通过归纳可知符合斐波那契数列。
Code:
1 | class Solution { |